package dao

import (
	"fmt"
	"lhy.org/custom_system/model"
)

var menus []model.Menu
var customs []*model.Custom = make([]*model.Custom, 0)

func init() {
	menus = make([]model.Menu, 0)
	menus = append(menus,
		model.Menu{
			Id:      1,
			Name:    "添 加 客 户",
			Display: true,
		}, model.Menu{
			Id:      2,
			Name:    "修改客户",
			Display: true,
		}, model.Menu{
			Id:      3,
			Name:    "删 除 客 户",
			Display: true,
		}, model.Menu{
			Id:      4,
			Name:    "客 户 列 表",
			Display: true,
		}, model.Menu{
			Id:      5,
			Name:    "退      出",
			Display: true,
		})
}

func AddCustom(custom *model.Custom) bool {
	var addBefore = len(customs)
	customs = append(customs, custom)
	var addAfter = len(customs)
	return addAfter-addBefore == 1
}

func DeleteCustom(custom *model.Custom) bool {
	var length = len(customs)
	r := customs[:0]
	for i := 0; i < length; i++ {
		if customs[i] != custom {
			r = append(r, customs[i])
		}
	}
	customs = r
	return false
}

func GetCustom(name string) *model.Custom {
	for _, custom := range customs {
		if name == custom.Name {
			return custom
		}
	}
	return nil
}

func ShowAllCustom() {
	for _, custom := range customs {
		fmt.Printf("%v\t%v\t%v\t%v\n", custom.Name, custom.Age, custom.Address, custom.Email)
	}
}

func ShowMenu() {
	for _, menu := range menus {
		fmt.Printf("%v %v\n", menu.Id, menu.Name)
	}
}
